from ..ModelInterface import Model, Widget, Param
from ..node import Node, Link
import time


class TestToNumber(Model):
    def get_title(self):
        return "字符转数字"

    def get_category(self):
        return "数字"

    def get_in(self):
        return [
            Param("字符串", "text"),
        ]

    def get_out(self):
        return [
            Param("数字", "number"),
        ]

    def get_widget(self):
        return [
            Widget("toggle", "整数开关", False, {"on": "打开", "off": "关闭"}),
        ]

    def process(self, node: Node, links: list[Link]) -> list[Link]:
        number = float(node.inputs[0].value)
        
        to_int = node.widgetValues[0]
        if to_int:
            number = int(number)
        
        node.outputs[0].value = number
        return links
